#include <bits/stdc++.h>
using namespace std;
int che[100000];
int cesu[100000];
void nb(int che[100000],int cesu[100000],int n,int m,int l,int v)
{
    int c=0,t=m;
    int gg[n+1];
    sort(cesu,cesu+m);
    for(int i=0;i<3*n;i+=3)
    {
        if(che[i]<=cesu[m-1] && che[i+1]>v)
        {
            c+=1;
            gg[c-1]=che[i];
        }
    }
    sort(gg,gg+c);
    for(int i=0;i<m;i+=1)
    {
        if(cesu[i]<gg[0]) t-=1;
    }
    cout<<c<<" ";
    if(c==0) cout<<m;
    else
    {
        cout<<m-t;
    }
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,n,m,l,v;
    cin>>t;
    for(int i=0;i<t;i+=1)
    {
        cin>>n>>m>>l>>v;
        for(int j=0;j<3*n;j+=3)
        {
            int di,vi,ai;
            cin>>di>>vi>>ai;
            che[j]=di;
            che[j+1]=vi;
            che[j+2]=ai;
        }
        for(int k=0;k<m;k+=1)
        {
            int p;
            cin>>p;
            cesu[k]=p;
        }
        nb(che,cesu,n,m,l,v);
        cout<<endl;
    }
/*    for(int i=0;i<t;i+=1)
    {
        for(int j=0;j<n*3;j+=3)
        {
            cout<<che[j]<<" "<<che[j+1]<<" "<<che[j+2]<<endl;
        }
        for(int k=0;k<m;k+=1)
        {
            cout<<cesu[k]<<" ";
        }
        cout<<endl;
    }*/
    return 0;
}
